package db.pojo;

import java.util.*;
import java.text.SimpleDateFormat;
import db.ext.ProductExt;
@SuppressWarnings("unchecked")
/**
 * product
 */
public class Product {
	/**
	 * PID
	 */
	public String pID;
	/**
	 * PNAME
	 */
	public String pNAME;
	/**
	 * SPEC
	 */
	public String sPEC;
	/**
	 * PURCHASEPRICE
	 */
	public String pURCHASEPRICE;
	/**
	 * PPRICE
	 */
	public String pPRICE;
	/**
	 * JOINTIME
	 */
	public String jOINTIME;
	/**
	 * PTOTAL
	 */
	public String pTOTAL;
	/**
	 * OTHER
	 */
	public String oTHER;
	/**
	 * CATEGORY
	 */
	public String cATEGORY;
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static ProductExt DB = new ProductExt(); 
	
	public Product() {
		super();
	}
	
	public Product(String pID, String pNAME, String sPEC, String pURCHASEPRICE, String pPRICE, String jOINTIME, String pTOTAL, String oTHER, String cATEGORY) {
		super();
		this.pID = pID; 
		this.pNAME = pNAME; 
		this.sPEC = sPEC; 
		this.pURCHASEPRICE = pURCHASEPRICE; 
		this.pPRICE = pPRICE; 
		this.jOINTIME = jOINTIME; 
		this.pTOTAL = pTOTAL; 
		this.oTHER = oTHER; 
		this.cATEGORY = cATEGORY; 
	}
	
	public String getPID() {
		return pID;
	}

	public void setPID(String pID) {
		this.pID = pID;
	} 
	
	public String getPNAME() {
		return pNAME;
	}

	public void setPNAME(String pNAME) {
		this.pNAME = pNAME;
	} 
	
	public String getSPEC() {
		return sPEC;
	}

	public void setSPEC(String sPEC) {
		this.sPEC = sPEC;
	} 
	
	public String getPURCHASEPRICE() {
		return pURCHASEPRICE;
	}

	public void setPURCHASEPRICE(String pURCHASEPRICE) {
		this.pURCHASEPRICE = pURCHASEPRICE;
	} 
	
	public String getPPRICE() {
		return pPRICE;
	}

	public void setPPRICE(String pPRICE) {
		this.pPRICE = pPRICE;
	} 
	
	public String getJOINTIME() {
		return jOINTIME;
	}

	public void setJOINTIME(String jOINTIME) {
		this.jOINTIME = jOINTIME;
	} 
	
	public String getPTOTAL() {
		return pTOTAL;
	}

	public void setPTOTAL(String pTOTAL) {
		this.pTOTAL = pTOTAL;
	} 
	
	public String getOTHER() {
		return oTHER;
	}

	public void setOTHER(String oTHER) {
		this.oTHER = oTHER;
	} 
	
	public String getCATEGORY() {
		return cATEGORY;
	}

	public void setCATEGORY(String cATEGORY) {
		this.cATEGORY = cATEGORY;
	} 
	
	
	public Map productToMap() {
		Map map = new HashMap();
		try {
			map.put("pID",this.pID);
			map.put("pNAME",this.pNAME);
			map.put("sPEC",this.sPEC);
			map.put("pURCHASEPRICE",this.pURCHASEPRICE);
			map.put("pPRICE",this.pPRICE);
			map.put("jOINTIME",this.jOINTIME);
			map.put("pTOTAL",this.pTOTAL);
			map.put("oTHER",this.oTHER);
			map.put("cATEGORY",this.cATEGORY);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	public Product mapToProduct(Map map){
		try {
			String pID =  map.get("pID").toString();
			String pNAME =  map.get("pNAME").toString();
			String sPEC =  map.get("sPEC").toString();
			String pURCHASEPRICE =  map.get("pURCHASEPRICE").toString();
			String pPRICE =  map.get("pPRICE").toString();
			String jOINTIME =  map.get("jOINTIME").toString();
			String pTOTAL =  map.get("pTOTAL").toString();
			String oTHER =  map.get("oTHER").toString();
			String cATEGORY =  map.get("cATEGORY").toString();
			Product product = new Product(pID, pNAME, sPEC, pURCHASEPRICE, pPRICE, jOINTIME, pTOTAL, oTHER, cATEGORY);
			return product;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	} 
	
	public String toString(){
		return productToMap().toString();
	}
	
	//方便数据操作	
	public Product insert(){
		return DB.insert(this);
	}
	public Product update(){
		return DB.update(this);
	}
	
	public int delete(){
		return DB.delete(this);
	}
	
}
